<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel  >
                        <f:facet name="header" >
                            <h:outputLabel value="OPD BILL ITEM "/>                                                         
                            <h:panelGrid columns="6" >
                                <h:outputLabel value="From Date"/>
                                <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                </p:calendar>
                                <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createBillItemTableByKeyword()}"/>
                                <p:commandButton id="btnSearchAll" ajax="false" value="SearchAll" action="#{searchController.createBillItemTableByKeywordAll()}" rendered="#{webUserController.hasPrivilege('SearchAll')}"/>
                                <p:commandButton value="Excel" ajax="false" styleClass="noPrintButton" style="float: right;">
                                    <pe:exporter type="xlsx" target="tblBills" fileName="Bill Item Report" />
                                </p:commandButton>
                                <p:spacer height="30"/><h:outputLabel/><h:outputLabel/><h:outputLabel/><h:outputLabel/>
                            </h:panelGrid>
                            <h:panelGrid columns="5" >
                                <h:outputLabel value="Bill No"/>
                                <h:outputLabel value="Item Name"/>
                                <h:outputLabel value="Patient Name"/>
                                <h:outputLabel value="Patient Phone"/>
                                <h:outputLabel value="Institution Name"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.itemName}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.patientName}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.patientPhone}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.toInstitution}" />
                            </h:panelGrid>

                        </f:facet>




                        <p:dataTable rowIndexVar="i" 
                                     id="tblBills" 
                                     value="#{searchController.billItems}" 
                                     var="pi"
                                     paginator="true"
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                     rowsPerPageTemplate="5,10,15"
                                     >
                            <p:column headerText="No" styleClass="alignTop">
                                <h:outputLabel value="#{i+1}"/>
                            </p:column>
                            <p:column headerText="Bill No" styleClass="alignTop" >
                                <h:commandLink action="bill_reprint" value="#{pi.bill.insId}">
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>   
                            </p:column>
                            <p:column headerText="Institution Name" styleClass="alignTop"  >
                                <h:commandLink action="bill_reprint" value="#{pi.bill.toInstitution.name}">
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Institution Name" styleClass="alignTop"  >
                                <h:commandLink action="bill_reprint" value="#{pi.bill.creditCompany.name}">
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>

                            <p:column headerText="Patient"  styleClass="alignTop"  >
                                <h:outputLabel value="#{pi.bill.patient.person.nameWithTitle}" >
                                </h:outputLabel>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <h:commandLink value="(edit)" action="patient" rendered="#{webUserController.hasPrivilege('OpdBillSearchEdit') and pi.bill.approvedAnyTest ne true}">
                                    <f:setPropertyActionListener value="#{pi.bill.patient}" target="#{patientController.current}"/>
                                </h:commandLink>
                                <br/>
                                <h:outputLabel value="#{pi.bill.patient.age}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="#{pi.bill.patient.person.sex}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="#{pi.bill.patient.person.phone}" >
                                </h:outputLabel>
                            </p:column>

                            <p:column headerText="Investigation/Service"  styleClass="alignTop"  >
                                <h:outputLabel value="#{pi.item.name}" >
                                </h:outputLabel>
                                <br/>
                                <h:outputLabel value="Billed at " />
                                <h:outputLabel value="#{pi.bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>

                                <h:panelGroup rendered="#{pi.bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.bill.cancelled}" value="#{pi.bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{pi.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded at " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.refunded}" value="#{pi.referanceBillItem.bill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <br/>
                            </p:column>
                            <p:column headerText="Billed by" >
                                <h:outputLabel value="#{pi.bill.creater.webUserPerson.name}" >                                      
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{pi.bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled By " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.bill.cancelled}" value="#{pi.bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{pi.bill.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded By " />
                                    <h:outputLabel style="color: red;" rendered="#{pi.bill.refunded}" value="#{pi.bill.refundedBill.creater.webUserPerson.name}" >
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>
                            <p:column headerText="Payment Method"   >
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{pi.bill.paymentMethod}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Discount Scheme" >
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{pi.bill.paymentScheme.name}" ></h:outputLabel>
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Gross Value"   >
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{pi.bill.total}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Discount"   >
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{pi.bill.discount}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Net Value"  >
                                <h:commandLink action="bill_reprint" >
                                    <h:outputLabel value="#{pi.bill.netTotal}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                    <f:setPropertyActionListener value="#{pi.bill}" target="#{billSearch.billSearch}"/>
                                </h:commandLink>
                            </p:column>
                            <p:column headerText="Comment" styleClass="alignTop"  >
                                <p:outputLabel value="#{pi.bill.comments}" />
                            </p:column>

                        </p:dataTable>

                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
